package com.cashmanager.server.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.log4j.Logger;


public class JDBCUtil{
	private final static Logger logger = Logger.getLogger(JDBCUtil.class);
    private final String URL = "jdbc:mysql://localhost:3306/cashms";
    private final String DRIVER = "com.mysql.jdbc.Driver";
    private final String USER_NAME = "root";
    private final String PASSWD = "1";
    private static JDBCUtil instance;
    
    private JDBCUtil(){
      try {
          Class.forName(DRIVER).newInstance();
      } catch (Exception e){
        e.printStackTrace();
      }
    }
    
    public static void closeConn(Connection conn){
    	if  (conn != null){
    		try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }
    
   public static JDBCUtil getInstance(){
     if (instance == null){
       instance = new JDBCUtil();
     }
     return instance;
    }
    
   public Connection getConnection() throws SQLException{
	   logger.debug("Begin getConnection()");
       Connection conn = DriverManager.getConnection(URL, USER_NAME, PASSWD);
       logger.debug("End getConnection()");
       return conn;
    }
}